<?php

namespace Modules\Custessa\Actions;

use CController as Action;
use CControllerResponseData;
use Modules\Custessa\Services\ContentOutput;

class ServeAction extends Action {

	protected $fields = [
		'c' => 'string|required',
	];

	protected function init() {
		$this->disableSIDvalidation();
	}

	protected function checkInput() {
		return $this->validateInput($this->fields);
	}

	protected function checkPermissions() {
		return true;
	}

	protected function doAction() {
		$this->setResponse((new CControllerResponseData([]))->disableView());

		$content_type = [
			'custessa.js' => ContentOutput::TYPE_JS,
			'custessa.css' => ContentOutput::TYPE_CSS,
		];
		$renderer = new ContentOutput;

		$renderer->render($content_type[$this->getAction()], $this->getInput('c'));

		exit;
	}
}
